package cn.larry.aop.config.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

/**
 * @author LarryZeal
 *
 */
@Profile("execution")
@Aspect
@Component
public class ExecutionAdvice {
	Logger logger = LoggerFactory.getLogger(ExecutionAdvice.class);

	@Before("cn.larry.aop.config.aspect.ExecutionAspect.anyMyPublicOperation2()")
	public void before(JoinPoint jp) {
		logger.info(jp.getSignature().toString());
	}

	/**
	 * 只有@Around才能注入ProceedingJoinPoint，其他的都是JoinPoint。
	 * 
	 * @param jp
	 * @return
	 */
	@Around(value = "cn.larry.aop.config.aspect.ExecutionAspect.anyMyPublicOperation3()")
	public Object around(ProceedingJoinPoint jp) {
		logger.info("around start");
		Object obj = null;
		try {
			obj = jp.proceed(new Object[] { "Huge" }); // 可以注入参数！！！
		} catch (Throwable e) {
			e.printStackTrace();
		}
		logger.info("around end");
		return obj;
	}
}
